import format from '@/util/timer';
import http from './../util/http';
import urlConcat from './url-concat';
import md5 from 'js-md5';
export default {
  async login(nickname: string, passwd: string) {
    const paramsUrl = urlConcat(`/user/nickname/login`, {
      nickname,
      passwd,
    });
    return http.post(paramsUrl);
  },
  async usersAdd(obj: any) {
    obj = JSON.parse(JSON.stringify(obj));
    obj.password = md5(obj.password);
    obj.roleIds = -1;
    const paramsUrl = urlConcat(`/user/addUser`, obj);
    return http.get(paramsUrl);
  },
  async usersDel(ids: string) {
    const paramsUrl = urlConcat(`/user/delUser`, {
      ids,
    });
    return http.get(paramsUrl);
  },
  async usersList(obj: any) {
    obj.startTime = format(obj.startTime) || '';
    obj.endTime = format(obj.endTime) || '';
    const paramsUrl = urlConcat(`/user/userQuery`, obj);
    return http.get(paramsUrl);
  },
  async usersUpdate(obj: any) {
    const paramsUrl = urlConcat(`/user/modifyUser`, obj);
    return http.post(paramsUrl);
  },
};
